/**
 * 购物车相关接口
 */
import type {PageQueryType, PageResultType} from "@/types/global";
import type {IProductBriefItem} from "@/types/product";
import {request} from "@/utils/http";

/**
 * 分页获取购物车列表的数据
 * @param page
 */
export const getShopCarListData = (page: PageQueryType) => {
    return request<PageResultType<IProductBriefItem>>({
        url: "/shopcar/page",
        method: "POST",
        data: page
    })
}

export const getShopCarStat = () => {
    return request<number>({
        url: "/shopcar/count",
        method: "GET"
    })
}
/**
 * 添加到购物车
 * @param skuId
 * @param count
 */
export const addToShopCar = (skuId: number, count: number) => {
    return request<number>({
        url: "/shopcar?id=" + skuId + "&count=" + count,
        method: "GET"
    })
}
/**
 * 从购物车中删除商品
 * @param id
 */
export const removeFromShopCar = (id: number) => {
    return request<number>({
        url: "/shopcar?id=" + id,
        method: "DELETE"
    })
}
/**
 * 修改购物车中商品的数量
 * @param skuId
 * @param count
 */
export const modifyCountForShopCar = (skuId: number, count: number) => {
    return request<number>({
        url: "/shopcar/modify-count?id=" + skuId + "&count=" + count,
        method: "GET"
    })
}
/**
 * 清空购物车
 */
export const clearAllForShopCar = () => {
    return request<number>({
        url: "/shopcar/empty",
        method: "DELETE"
    })
}